package com.aseo.business;

import java.sql.Timestamp;
import java.util.List;
import java.util.Set;

import javax.annotation.Resource;
import javax.validation.ConstraintViolation;

import org.springframework.stereotype.Service;

import com.aseo.exception.ConstraintViolationException;
import com.aseo.model.dao.Dao;
import com.aseo.model.entity.ReclamoNota;

//@Service
public class ReclamoNotaManager {

	@Resource  
	private Dao dao;
	
	public ReclamoNota newReclamoNota() {  
		return new ReclamoNota();  
	}  
	  
	public void persist(ReclamoNota reclamoNota) {
		reclamoNota.setFechaHora(new Timestamp(System.currentTimeMillis()));
		dao.persist(reclamoNota);
	}
	  
	public List<ReclamoNota> getReclamoNotas() {  
		final List<ReclamoNota> list = dao.find(ReclamoNota.class);  
	    return list;
	}

	public ReclamoNota get(Long idReclamoNota) {
		return dao.get(ReclamoNota.class, idReclamoNota);
	}
	
	public void validate(ReclamoNota reclamoNota) throws ConstraintViolationException {

		Set<ConstraintViolation<ReclamoNota>> constraintViolations = dao.validate(reclamoNota);
		
		for (ConstraintViolation<ReclamoNota> constraintViolation : constraintViolations) {
			throw new ConstraintViolationException(constraintViolation.getMessage());
		}
	}

}